﻿Imports System.Data.OleDb
Public Class ThanhToanTheDAO
    Shared conn_str As String = My.Settings.ConnectionString
    Shared Sub TraNo(SoTien As Double, MaNganHang As Integer)
        Dim query As String = "update TaiKhoanNganHang set sotien = sotien - ? where MaUser = ? AND MaNganHang = ?"
        Try
            Dim conn As New OleDbConnection(conn_str)
            conn.Open()
            Dim dt = DB_Provider.Read_schema("PhieuChi")
            Dim dr As DataRow = dt.NewRow()
            dr.Item("Ngay") = Date.Now.ToString("yyyy-MM-dd")
            dr.Item("SoTien") = SoTien
            dr.Item("MaUserChi") = MainForm.current_user.MaUser
            dr.Item("MaUserLap") = MainForm.current_user.MaUser
            dr.Item("MaNganHang") = MaNganHang
            dr.Item("MaChiPhi") = 0
            dr.Item("ChiTiet") = "the_tin_dung"
            dt.Rows.Add(dr)
            DB_Provider.Write(dt, "PhieuChi")

            Dim cmd As New OleDbCommand(query, conn)
            cmd.Parameters.AddWithValue("@sotien", SoTien)
            cmd.Parameters.AddWithValue("@MaUser", MainForm.current_user.MaUser)
            cmd.Parameters.AddWithValue("@MaNganHang", MaNganHang)
            cmd.ExecuteNonQuery()
            conn.Close()
        Catch Loi As CustomException.MyException
            Loi.Show(query, conn_str)
        End Try
    End Sub
End Class
